package Presentacion.notas;

import clases.notas.Curso;
import clases.notas.Excel;
import global.Iconos;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;

public class dlgnotas extends javax.swing.JDialog {

    private Iconos ico = new Iconos();
    Curso c = new Curso();
    DefaultTableModel modelo;

    /**
     * Creates new form dlgnotas
     */
    public dlgnotas(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(this);
        this.setTitle("Carga de Notas");
        this.iconos();
        this.generarModelo();
        c.listarCursoActivoCombo(cbocurso);
    }

    private void generarModelo() {
        modelo = new DefaultTableModel();
        modelo.addColumn("Cedula");
        modelo.addColumn("No.");
        modelo.addColumn("Alumno");
        modelo.addColumn("TRA 1");
        modelo.addColumn("TRA 2");
        modelo.addColumn("TRA 3");
        modelo.addColumn("TRA 4");
        modelo.addColumn("TRA 5");
        modelo.addColumn("PRO");

        modelo.addColumn("ACT 1");
        modelo.addColumn("ACT 2");
        modelo.addColumn("ACT 3");
        modelo.addColumn("ACT 4");
        modelo.addColumn("ACT 5");
        modelo.addColumn("PRO");

        modelo.addColumn("GRP 1");
        modelo.addColumn("GRP 2");
        modelo.addColumn("GRP");

        modelo.addColumn("LEC 1");
        modelo.addColumn("LEC 2");
        modelo.addColumn("LEC 3");
        modelo.addColumn("LEC 4");
        modelo.addColumn("PRO");

        modelo.addColumn("EVAL 1");
        modelo.addColumn("PRO ");
        modelo.addColumn("CLTA ");



    }

    private void formatearTabla() {
        tblnotas.getColumnModel().getColumn(0).setMaxWidth(0);
        tblnotas.getColumnModel().getColumn(0).setMinWidth(0);
        tblnotas.getColumnModel().getColumn(0).setPreferredWidth(0);

        tblnotas.getColumnModel().getColumn(2).setPreferredWidth(370);
    }

    private void iconos() {
        btnnuevo.setIcon(ico.getNuevo());
      //  btnnuevo.setText("");
        btnguardar.setIcon(ico.getGuardar());
       // btnguardar.setText("");
        btnsalir.setIcon(ico.getSalir());
    //    btnsalir.setText("");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cbocurso = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblnotas = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtdocente = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        cboasignatura = new javax.swing.JComboBox();
        cboquimestre = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        cboparcial = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        btnnuevo = new javax.swing.JButton();
        btnguardar = new javax.swing.JButton();
        btnsalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("CURSO");

        cbocurso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbocurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbocursoActionPerformed(evt);
            }
        });

        tblnotas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "cedula", "No.", "ALUMNO", "TRA 1", "TRA 2", "TRA 3", "TRA 4", "TRA 5", "PRO", "ACT 1", "ACT 2", "ACT 3", "ACT 4", "ACT 5", "PRO", "GRP 1", "GRP 2", "PRO", "LEC 1", "LEC 2", "LEC 3", "LEC 4", "PRO", "EVAL", "CLTA", "PRO"
            }
        ));
        jScrollPane1.setViewportView(tblnotas);

        jLabel3.setText("ASIGNATURA");

        jLabel4.setText("DOCENTE");

        txtdocente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtdocenteActionPerformed(evt);
            }
        });

        jLabel5.setText("QUIMESTRE");

        cboasignatura.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-", " " }));
        cboasignatura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboasignaturaActionPerformed(evt);
            }
        });

        cboquimestre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- SELECCIONE --", "1", "2" }));

        jLabel7.setText("PARCIAL");

        cboparcial.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- SELECCIONE --", "1", "2", "3", "4", "5" }));

        jButton1.setText("Cargar Excel");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cboasignatura, 0, 364, Short.MAX_VALUE)
                            .addComponent(cbocurso, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(cboquimestre, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel4)
                                .addGap(36, 36, 36)
                                .addComponent(txtdocente, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(76, 76, 76)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(cboparcial, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1229, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(cbocurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(cboparcial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(cboasignatura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(cboquimestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(23, 23, 23))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtdocente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jToolBar1.setFloatable(false);

        btnnuevo.setText("Nuevo");
        btnnuevo.setFocusable(false);
        btnnuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnnuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btnnuevo);

        btnguardar.setText("Guardar");
        btnguardar.setFocusable(false);
        btnguardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnguardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btnguardar);

        btnsalir.setText("Salir");
        btnsalir.setFocusable(false);
        btnsalir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnsalir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btnsalir);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtdocenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtdocenteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtdocenteActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        JFileChooser jf = new JFileChooser();

        FileNameExtensionFilter filtro = new FileNameExtensionFilter("xls", "xlsx");
        jf.setFileFilter(filtro);
        jf.showOpenDialog(null);

        Excel xls = new Excel(jf.getSelectedFile().getAbsolutePath());

        xls.leerNotas(modelo, 17);


    }//GEN-LAST:event_jButton1ActionPerformed

    private void cbocursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbocursoActionPerformed
        if (cbocurso.getSelectedIndex() != 0 && cbocurso.getSelectedIndex() != -1) {
            this.generarModelo();
            c.listaMateriaAsignada(this.cboasignatura, this.cbocurso.getSelectedItem().toString());
            c.listaAlumnoCurso(tblnotas, modelo, cbocurso.getSelectedItem().toString());
            this.formatearTabla();
            getDocente();
        }
    }//GEN-LAST:event_cbocursoActionPerformed

    private void cboasignaturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboasignaturaActionPerformed
        if (cboasignatura.getSelectedIndex() != 0 && cboasignatura.getSelectedIndex() != -1) {
            getDocente();
        }
    }//GEN-LAST:event_cboasignaturaActionPerformed

    private void getDocente() {
        if (cbocurso.getSelectedIndex() != 0 && cbocurso.getSelectedIndex() != -1 && cboasignatura.getSelectedIndex() != 0 && cboasignatura.getSelectedIndex() != -1) {
            this.txtdocente.setText(c.getDocenteMateria(cbocurso.getSelectedItem().toString(), cboasignatura.getSelectedItem().toString()));
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(dlgnotas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(dlgnotas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(dlgnotas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(dlgnotas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                dlgnotas dialog = new dlgnotas(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnguardar;
    private javax.swing.JButton btnnuevo;
    private javax.swing.JButton btnsalir;
    private javax.swing.JComboBox cboasignatura;
    private javax.swing.JComboBox cbocurso;
    private javax.swing.JComboBox cboparcial;
    private javax.swing.JComboBox cboquimestre;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTable tblnotas;
    private javax.swing.JTextField txtdocente;
    // End of variables declaration//GEN-END:variables
}
